package com.fy56.platform.logistics.service.impl;

import com.fy56.platform.logistics.common.ResultModel;
import com.fy56.platform.logistics.common.ResultStatus;
import com.fy56.platform.logistics.mapper.VipBankMapper;
import com.fy56.platform.logistics.model.VipBank;
import com.fy56.platform.logistics.service.wx.IVipBankService;
import com.fy56.platform.logistics.utils.IdWorkerTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * VIP用户银行Service
 * Created by li on 2018-01-29.
 */
@Service
public class VipBankServiceImpl implements IVipBankService {

    @Autowired
    private VipBankMapper vipBankMapper;

    @Override
    public VipBank selectByPrimaryKey(Long id) {
        return null;
    }

    @Override
    public VipBank get(VipBank entity) {
        return null;
    }

    /**
     * 根据用户ID货物银行列表
     *
     * @param vipMemberId
     * @return
     */
    @Override
    @Transactional(readOnly = true)
    public List<VipBank> select(Long vipMemberId){
        return vipBankMapper.select(vipMemberId);
    }

    /**
     * 根据银行卡号获取银行列表
     *
     * @param model
     * @return
     */
    @Override
    @Transactional(readOnly = true)
    public List<VipBank> selectByCardNo(VipBank model){
        return vipBankMapper.selectByCardNo(model);
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel insert(VipBank entity) {
        ResultModel result = null;
        entity.setId(Long.valueOf(IdWorkerTools.getInstance().getId()));
        int r = vipBankMapper.insert(entity);
        if(r == 0) {
            result = ResultModel.error(ResultStatus.INSERT_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    public ResultModel insertSelective(VipBank entity) {
        return null;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel update(VipBank entity) {
        ResultModel result = null;
        int r = vipBankMapper.updateByPrimaryKey(entity);
        if (r == 0) {
            result = new ResultModel(ResultStatus.EDIT_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel updateSelective(VipBank entity) {
        ResultModel result = null;
        int r = vipBankMapper.updateByPrimaryKeySelective(entity);
        if (r == 0) {
            result = new ResultModel(ResultStatus.EDIT_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel delete(Long id) {
        ResultModel result = null;
        int r = vipBankMapper.deleteByPrimaryKey(id);
        if (r == 0) {
            result = new ResultModel(ResultStatus.DELETE_ERR);
        }else {
            result = ResultModel.ok();
        }
        return result;
    }

    @Override
    public ResultModel delete(VipBank entity) {
        return null;
    }

    @Override
    public List<VipBank> findList(VipBank entity) {
        return null;
    }

}
